// pages/cart/childCpns/y-cart-list-item/y-cart-list-item.js
const app = getApp();

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    goods: {
      type: Object,
      value: {},
    },
    index: {
      type: Number,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    onCheckClick(e) {
      // 1. 查找到对应的商品
      const goods = app.globalData.cartList.find(
        (item) => item.iid === this.propertyies.goods.iid
      );
      goods.checked = !goods.checked;
      // 2. 获取当前商品的 index
      const index = e.currentTarget.dataset.index;
      app.changeGoodsState(index, goods);
    },
  },
});
